<template>
	<view class="prescriptionList-wrap">
		<view class="prescriptionList-label" v-if="dataList.length > 0">
			<u-title value="我的处方列表"></u-title>
			<scroll-view show-scrollbar="false" class="scroll-list " scroll-y @scrolltolower="scrollLoading()">
				<u-presc-item
					v-for="(item, index) in dataList"
					:key="index"
					:data="item"
					type="3"
					btnText="使用处方"
					@click="gotoRouter('/pages-doctor/prescInfo/prescInfo?id=' + item.id + '&role=0')"
					@clickOne="gotoRouter('/pages-mall/orderCreate/orderCreate?orderCode=' + item.drugOrderCode)"
				></u-presc-item>
			</scroll-view>
		</view>
		<u-empty-state v-if="dataTotalPage == 0" value="暂无相关处方"></u-empty-state>
		<uni-load-more v-if="dataTotalPage > 1" :status="dataLoading"></uni-load-more>
	</view>
</template>

<script>
import uTitle from '@/components/u-title/u-title.vue';
import uPrescItem from '@/components/u-presc-item/u-presc-item.vue';
import uniLoadMore from '@/components/uni/uni-load-more/uni-load-more.vue';
import uEmptyState from '@/components/u-empty-state/u-empty-state.vue';
export default {
	components: {
		uTitle,
		uniLoadMore,
		uEmptyState,
		uPrescItem
	},
	data() {
		return {
			pageNo: 1,
			pageSize: 20,
			dataTotalPage: 1, //数据总数
			dataLoading: 'loading', //数据加载
			dataList: []
		};
	},
	onLoad(option) {},
	onShow() {
		this.initData();
	},
	methods: {
		initData(e) {
			this.pageNo = 1;
			this.dataList = [];
			this.dataTotalPage = 1;

			this.scrollLoading();
		},

		//问诊订单列表
		queryUserRecipePage() {
			this.$api
				.queryUserRecipePage({
					params: {
						pageNo: this.pageNo,
						pageSize: this.pageSize
					}
				})
				.then(res => {
					if (res.code == 200) {
						res.result.records.forEach(key => {
							key.recipeDetailDTO = JSON.parse(key.content);
						});
						this.dataTotalPage = res.result.pages;

						if (this.pageNo == 1) {
							this.dataList = res.result.records;
						} else {
							this.dataList = this.dataList.concat(res.result.records);
						}

						if (res.result.current >= res.result.pages) {
							this.dataLoading = 'noMore';
						} else {
							this.dataLoading = 'loading';
						}
						this.pageNo++;
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				});
		},

		//滚动加载
		scrollLoading() {
			if (this.pageNo <= this.dataTotalPage) {
				this.queryUserRecipePage();
			}
		}
	}
};
</script>

<style lang="less">
@import './prescriptionList.less';
</style>
